package com.rao.travel.dao;

import com.rao.travel.pojo.Member;
import com.rao.travel.pojo.Orders;
import com.rao.travel.pojo.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Srao
 * @version 1.0
 * @className OrdersDao
 * @date 2019/10/29 11:16
 * @package com.rao.travel.dao
 * @description
 */
@Mapper
public interface OrdersDao {
    /*查询所有订单信息*/
    @Select("select * from orders")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "productId", property = "product", javaType = Product.class, one = @One(select = "com.rao.travel.dao.ProductDao.findById"))
    })
    List<Orders> findAll() throws Exception;

    /*查看订单详情*/
    @Select("select * from orders where id = #{id}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "productId", property = "product", javaType = Product.class, one = @One(select = "com.rao.travel.dao.ProductDao.findById")),
            @Result(column = "memberId", property = "member", javaType = Member.class, one = @One(select = "com.rao.travel.dao.MemberDao.findById")),
            @Result(column = "id", property = "travellers", javaType = java.util.List.class, many = @Many(select = "com.rao.travel.dao.travellerDao.findByOrdersId"))
    })
    Orders findById(String id) throws Exception;
}
